package com.ct.controller;

import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ct.entity.po.Schedule;
import com.ct.entity.query.ScheduleQuery;
import com.ct.entity.vo.ResponseVO;
import com.ct.service.ScheduleService;

import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;

/**
 * 行程表 Controller
 */
@RestController("scheduleController")
@RequestMapping("/schedule")
public class ScheduleController extends ABaseController {

    @Resource
    private ScheduleService scheduleService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadDataList")
    public ResponseVO loadDataList(ScheduleQuery query) {
        return getSuccessResponseVO(scheduleService.findListByPage(query));
    }

    /**
     * 新增
     */
    @RequestMapping("/add")
    public ResponseVO add(@NotEmpty String location, @NotEmpty String task, @NotEmpty String scheduleDetail,
            @NotEmpty Date startDate, @NotEmpty Date endTime) {
        Schedule bean = new Schedule(null, location, task, scheduleDetail, startDate, endTime, null);
        scheduleService.add(bean);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增
     */
    @RequestMapping("/addBatch")
    public ResponseVO addBatch(@RequestBody List<Schedule> listBean) {
        scheduleService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增/修改
     */
    @RequestMapping("/addOrUpdateBatch")
    public ResponseVO addOrUpdateBatch(@RequestBody List<Schedule> listBean) {
        scheduleService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据ScheduleId查询对象
     */
    @RequestMapping("/getScheduleByScheduleId")
    public ResponseVO getScheduleByScheduleId(Integer scheduleId) {
        return getSuccessResponseVO(scheduleService.getScheduleByScheduleId(scheduleId));
    }

    /**
     * 根据ScheduleId修改对象
     */
    @RequestMapping("/updateScheduleByScheduleId")
    public ResponseVO updateScheduleByScheduleId(Schedule bean, Integer scheduleId) {
        scheduleService.updateScheduleByScheduleId(bean, scheduleId);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据ScheduleId删除
     */
    @RequestMapping("/deleteScheduleByScheduleId")
    public ResponseVO deleteScheduleByScheduleId(Integer scheduleId) {
        scheduleService.deleteScheduleByScheduleId(scheduleId);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/getAllScheduleListByTravelId")
    public ResponseVO getAllScheduleListByTravelId(@RequestParam Integer travelId) {
        return getSuccessResponseVO(scheduleService.getAllScheduleListByTravelId(travelId));
    }
}